<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item v-if="!$store.state.user.MerchantId">
          <el-select v-model="dataForm.merchantId" placeholder="商户" clearable>
            <el-option
              :value="item.id"
              v-for="item in shs"
              :key="item.id"
              :label="item.name"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.status" placeholder="订单状态" clearable>
            <el-option
              :value="item.value"
              v-for="item in status"
              :key="item.value"
              :label="item.label"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @sort-change="dataListSortChangeHandle"
      >
        <el-table-column
          prop="invoiceName"
          label="发票明细-名称"
          header-align="center"
          align="center"
          width="180"
          :show-overflow-tooltip="true"
        ></el-table-column>

        <el-table-column
          prop="invoiceTitle"
          label="发票抬头"
          width="200"
          :show-overflow-tooltip="true"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="type"
          label="抬头类型"
           min-width="120"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{ scope.row.type | type }}
          </template>
        </el-table-column>
        <el-table-column
          prop="invoicePrice"
          label="发票金额(元)"
          min-width="100"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="invoiceDate"
          label="开票时间"
          header-align="center"
          min-width="150"
          align="center"
        ></el-table-column>

        <!-- <el-table-column
          prop="taxNumber"
          label="税号"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="开户银行"
          label="开户银行"
          :show-overflow-tooltip="true"
          header-align="center"
          min-width="150"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="bankAccount"
          label="银行账号"
          min-width="150"
          header-align="center"
          align="center"
        ></el-table-column> -->
        <!-- <el-table-column
          prop="unitAddress"
          label="单位地址"
          header-align="center"
          min-width="180"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="unitPhone"
          label="单位电话号码"
          header-align="center"
          min-width="180"
          align="center"
        ></el-table-column> -->
        <el-table-column
          prop="guestPhone"
          label="手机号"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="email"
          label="邮箱"
          header-align="center"
          min-width="140"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          min-width="100"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <span style="color: #13ce66;" v-if="scope.row.status==1">已开票</span>
            <span style="color: #666;" v-else>未开票</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="createDate"
          label="申请时间"
          header-align="center"
          min-width="150"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="status"
          label="是否开票"
          min-width="100"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-switch
              @change="
                (val) => changeStatus(scope.row)
              "
              :value="scope.row.status"
              :active-value="0"
              :inactive-value="1"
              :disabled="scope.row.status == 1 ? true : false"
              active-color="#ddd"
              inactive-color="#13ce66"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="120"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="lookDetail(scope.row.id)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
       <detail ref="lookDetail" v-if="lookDetailVisible"> </detail>
    </div>
  </el-card>
</template>
    
    <script>
var that;
import mixinViewModule from "@/mixins/view-module";
import detail from "./isinvoice-detail";
export default {
  mixins: [mixinViewModule],
  components: {
    detail,
  },
  filters: {
    orderStatus(val) {
      if (val || val === 0) {
        let d = that.status.filter((item) => item.value == val);
        if (d.length != 0) {
          return d[0].label;
        }
      }
    },
    type(val) {
      if (val || val === 0) {
        let d = that.types.filter((item) => item.value == val);
        if (d.length != 0) {
          return d[0].label;
        }
      }
    },
  },
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/api/isinvoice/page",
        getDataListIsPage: true,
        deleteURL: "/api/isinvoice",
        deleteIsBatch: true,
      },
      status: [
        {
          label: "未开票",
          value: 0,
        },
        {
          label: "已开票",
          value: 1,
        },
      ],
      types: [
        {
          label: "企业",
          value: 0,
        },
        {
          label: "个人/非企业单位",
          value: 1,
        },
      ],
      shs: [],
      dataForm: {
        // name: '',
        invoiceType: 10,
        orderCode: "",
        status: "",
        merchantId:
          this.$store.state.user.MerchantId ||
          localStorage.getItem("MerchantId"),
        // status: '',
        // activity: '',
        // islandId: '',
        // linkName: '',
        // phone: '',
        // openId:''
      },
    };
  },
  created() {
    that = this;
    if (this.$store.state.user.MerchantId) {
      this.getDataList();
    } else {
      this.getSh();
    }
  },
  methods: {
    changeStatus(item) {
      if(item.status==1) return
      this.$confirm(`是否确定开票？一旦开票将无法撤回！`, this.$t("prompt.title"), {
        confirmButtonText: this.$t("confirm"),
        cancelButtonText: this.$t("cancel"),
        type: "warning",
      })
        .then(() => {
          item.status = 1;
          item.invoiceDate = new Date().Format('yyyy-MM-dd hh:mm:ss');
          this.$http.put("/api/isinvoice", item).then((res) => {
            if (res.data.code !== 0) {
              return this.$message.error(res.data.msg);
            }
            this.$message({
              message: this.$t("prompt.success"),
              type: "success",
              duration: 500,
              onClose: () => {
                this.getDataList();
              },
            });
          });
        })
        .catch(() => {
          item.status = 0;
        });
    },
    getSh() {
      this.$http
        .get("/scenic/merchant/info/page", {
          params: {
            page: 1,
            limit: 50,
            merchantCategory: 10,
            status: 1,
          },
        })
        .then((res) => {
          if (res.data.code == 0) {
            this.shs = res.data.data.list;
            this.dataForm.merchantId = this.shs[0].id;
            this.getDataList();
          }
        });
    },
    mianpin(id) {
      this.$confirm("确定该操作？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http.get("/scenic/order/noSpell/" + id).then((res) => {
            if (res.data.code == 0) {
              this.$message({
                type: "success",
                message: "操作成功!",
              });
              this.getDataList();
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {});
    },
  },
};
</script>
    